<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<script language="javascript" src="funcoes.js"></script>

<fieldset>
    <legend>
        Pesquisa
    </legend> 
    <form action="Controller?action=PesquisaFaturamento" method="POST">
        <input type="hidden" name="idProfissional" value="${sessionScope.profissional.idProfissional}" />
        <p>Dta. Inicial..: <input type="text" name="cpDataInicio" value="" maxlength="16" onkeypress="formata_mascara(this, '##/##/#### ##:##'); return Numero(event);" /><i style="color: red;">Ex.: ddMMyyyy HHmm</i><br /></p> 
        <p>Dta. Final...: <input type="text" name="cpDataFim" value="" maxlength="16" onkeypress="formata_mascara(this, '##/##/#### ##:##'); return Numero(event);" /><i style="color: red;">Ex.: ddMMyyyy HHmm</i></p>
        <input type="submit" value="Pesquisar" />
    </form>
</fieldset>

<table border="1" style= "width: 100%">
    <thead style="background: black; color: white">
        <tr>
            <th>Data/Horario</th>
            <th>Paciente</th>
            <th>Servico</th>
            <th>Valor</th>      
        </tr>
    </thead>
    <tbody>
        <c:forEach items="${requestScope.ListaConsulta}" var="cons"> 
            <tr>                
                <c:forEach items="${requestScope.ListaPaciente}" var="p"> 
                    <c:if test="${p.idPaciente == cons.agenda.paciente.idPaciente}">
                        <th><f:formatDate value="${cons.agenda.data}" pattern="dd/MM/yyyy HH:mm"/></th>
                        <th>${p.nome}</th>
                    </c:if>
                </c:forEach>
                
                <c:forEach items="${requestScope.ListaServico}" var="serv"> 
                    <c:if test="${serv.idServico == cons.servico.idServico}">
                        <c:set var="total" value="${total + serv.valor}" />
                        <th>${serv.descricao}</th>
                        <th>${serv.valor}</th>
                    </c:if>
                </c:forEach>
            </tr>                            
        </c:forEach>
    </tbody>    
</table>

<h3 align="center" style="color: black; background-color: #eeeeee;">Total: R$ ${total}</h3> 

<h3 style="color: red">${requestScope.msg}</h3>